package com.data2wisdom.comm.base.model;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import com.github.pagehelper.PageInfo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
/**
 * API相应模型
 * @author LV
 * @param <T>
 */
@ApiModel(value = "API响应模型对象")
public class APIResponse<T> {
    public static final int SUCCESS = 0;//请求状态
    public static final int FAIL = -1;
    @ApiModelProperty(value = "消息编号：0=成功，<0表示异常")
    private int msgCode = SUCCESS;
    @ApiModelProperty(value = "消息内容")
    private String msg = "成功";
    @ApiModelProperty(value = "API数据")
    private List<T> data = new ArrayList<T>();//返回集合对象
    private T object;//返回单个对象
    private long total;//总记录数
    private long iTotalDisplayRecords; 
    private long iTotalRecords;
    private int totalPage;//总页数
    private int currPage;//当前页
    private Timestamp nowTime;
    /**
     * 构造函数：分页数据
     * @param pageData
     */
    public APIResponse(PageDto<T> pageData) {
    	if (null!=pageData) {
    		data=pageData.getData();
    		total=pageData.getTotal();
    		totalPage=pageData.getTotalPage();
    		currPage=pageData.getCurrPage();
		}
    }
    /**
     * 构造函数：分页数据
     * @param pageData
     */
    public APIResponse(PageInfo<T> pageInfo) {
    	if (null!=pageInfo) {
    		data=pageInfo.getList();
    		total=pageInfo.getTotal();
    		iTotalDisplayRecords=pageInfo.getTotal();
    		iTotalRecords=pageInfo.getTotal();
    		totalPage=pageInfo.getPages();
    		currPage=pageInfo.getPageNum();
		}
    }
    
    
    
    /**
     * 构造函数：集合数据
     * @param data
     */
    public APIResponse(List<T> data) {
    	if (null!=data) {
    		this.data=data;
    		total=data.size();
		}
    }
    /**
     * 构造函数：自定义分页数据
     * @param data
     * @param total
     * @param totalPage
     * @param currPage
     */
    public APIResponse(List<T> data,Long total,int totalPage,int currPage) {
    	if (null!=data) {
    		this.data=data;
    		this.total=total;
    		this.totalPage=totalPage;
    		this.currPage=currPage;
		}
    }
    /**
     * 构造函数：单个模型数据
     * @param returnData
     */
    public APIResponse(T returnData) {
    	object=returnData;
    }
    /**
     * 构造函数：单个消息
     * @param msg
     */
    public APIResponse(String msg) {
        this.msg = msg;
    }
    /**
     * 构造函数：消息和消息码
     * @param msg
     */
    public APIResponse(int msgCode, String msg) {
        this.msgCode = msgCode;
        this.msg = msg;
    }
    
    
    public int getMsgCode() {
        return msgCode;
    }

    public void setMsgCode(int msgCode) {
        this.msgCode = msgCode;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public List<T> getData() {
        return data;
    }

    public void setDatas(List<T> data) {
        this.data = data;
    }

	public long getTotal() {
		return total;
	}

	public void setTotal(long total) {
		this.total = total;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public int getCurrPage() {
		return currPage;
	}

	public void setCurrPage(int currPage) {
		this.currPage = currPage;
	}
	public T getObject() {
		return object;
	}
	public void setObject(T object) {
		this.object = object;
	}
	public long getiTotalDisplayRecords() {
		return iTotalDisplayRecords;
	}
	public void setiTotalDisplayRecords(long iTotalDisplayRecords) {
		this.iTotalDisplayRecords = iTotalDisplayRecords;
	}
	public long getiTotalRecords() {
		return iTotalRecords;
	}
	public void setiTotalRecords(long iTotalRecords) {
		this.iTotalRecords = iTotalRecords;
	}
	public Timestamp getNowTime() {
		return nowTime;
	}
	public void setNowTime(Timestamp nowTime) {
		this.nowTime = nowTime;
	}
}
